package com.qingke.easyjava.jdbc.util;

import java.util.Scanner;

public class QingkeConsole {

	public static void println(String msg) {
		System.out.println(msg);
	}
	
	public static void println(Object obj) {
		System.out.println(obj);
	}
	
	public static Scanner scanner = new Scanner(System.in);
	public static String askUserInput(String msg) {
		
		String input = null;
		while(true) {
			//print 光标在内容的后面，println 打印结束后，会有一个回车符
			System.out.print(msg + ">"); 
			input = scanner.nextLine();
			
			//trim -去掉前后空格
			if(input != null && input.trim().length() > 0) {
				break;
			}
			
			System.out.println("Please enter a non-emplty string!");
		}
		
		return input;
	}
	
	public static int askUserInputInt(String msg) {
		
		int inputInt = -1;
		while(true) {
			String input = askUserInput(msg);
			//String 转换成int
			try {
				inputInt = Integer.valueOf(input);
				break;
			}catch (NumberFormatException e) {
				System.out.println("Please enter a number value");
			}
		}
		return inputInt;
	}
	
	public static void terminate() {
		System.out.println("Bye-Bye");
		System.exit(0);
	}
}
